package com.tanglinkai.mall.service.impl;

import com.tanglinkai.mall.entity.po.Supplier;
import com.tanglinkai.mall.mapper.SupplierMapper;
import com.tanglinkai.mall.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierMapper supplierMapper;

    /**
     * 添加供应商
     * @param supplier
     */
    @Override
    public void addSupplier(Supplier supplier) {
        supplierMapper.addSupplier(supplier);
    }

    /**
     * 获取所有供应商
     * @return
     */
    @Override
    public List<Supplier> getAllSuppliers() {
        return supplierMapper.getAllSuppliers();
    }

    /**
     * 删除供应商
     * @param id
     */
    @Override
    public void deleteSupplierById(Integer id) {
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("ID无效");
        }

        Supplier supplier = supplierMapper.getSupplierById(id);
        if (supplier == null) {
            throw new IllegalArgumentException("供应商不存在");
        }

        supplierMapper.deleteSupplierById(id);
    }
}
